package com.itheima.mapper;

import com.itheima.pojo.Order;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;
import java.util.List;

@Mapper
public interface OrderMapper {

    /**
     * 保存预约信息
     * @param order
     */
    @Insert("insert into t_order (member_id, order_date, order_type, order_status, setmeal_id) " +
            "VALUES (#{memberId},#{orderDate},#{orderType},#{orderStatus},#{setmealId})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void insert(Order order);

    /**
     * 根据id查询预约信息
     * @param id
     * @return
     */
    @Select("select id, member_id, order_date, order_type, order_status, setmeal_id" +
            " from t_order where id = #{id}")
    Order selectById(Integer id);

    /**
     * 根据用户id和预约日期和套餐id查询预约记录
     * @param memberId
     * @param orderDate
     * @param setmealId
     * @return
     */
    @Select("select count(*) from t_order where member_id = #{memberId} and order_date = #{orderDate} and setmeal_id = #{setmealId}")
    Integer countByMemberIdAndDateWithSetmeal(Integer memberId, LocalDate orderDate, Integer setmealId);
}
